﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Wicresoft.Common;
using Monthly.Framework.BusinessLogic;
using MonthlyDB.Entity;

public partial class Page_MonthlyList1 : BaseAuthenticationPage
{
    public string SearchClauseList
    {
        get
        {
            if (ViewState["SearchClauseList"] == null)
                ViewState["SearchClauseList"] = "1=1";
            return ViewState["SearchClauseList"].ToString();
        }
        set
        {
            ViewState["SearchClauseList"] = value;
        }
    }

    protected DataTable dtMonthlyList
    {
        get
        {
            if (ViewState["dtMonthlyList"] == null)
                ViewState["dtMonthlyList"] = new DataTable();
            return ViewState["dtMonthlyList"] as DataTable;
        }
        set
        {
            ViewState["dtMonthlyList"] = value;
        }
    }

    public Guid DeptID
    {
        get
        {
            Guid gd = Guid.Empty;
            try
            {
                gd = new Guid(Request["ID"] ?? Guid.Empty.ToString());
            }
            catch (System.Exception ex)
            {
            	    
            }
            return gd;
        }
       
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "科室周报管理";

        this.tbDateStart.Attributes.Add("readonly", "readonly");
        this.tbDateEnd.Attributes.Add("readonly", "readonly");
        if (!IsPostBack)
        {
            this.Order.OrderColumn = "CreateTime";
            this.Order.OrderDirection = "DESC";
            Depts dept = new Depts();
            dept.ID = DeptID;
            if (dept.Load())
            {
                ltlHeader.Text = dept.DeptName;
            }
        }
    }

    protected override void Pager_PageChanged(object sender, EventArgs e)
    {
        BindData();
        base.Pager_PageChanged(sender, e);
    }

    protected override void Order_OrderChanged(object sender, EventArgs e)
    {
        BindData();
        base.Order_OrderChanged(sender, e);
    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindData();
    }



    private void BindData()
    {
        int recordCount = 0;
        dtMonthlyList = BLMonthly.GetMonthlyList(DeptID, SearchClauseList, Pager.PageIndex, Pager.PageSize, string.Format("{0} {1}", this.Order.OrderColumn, this.Order.OrderDirection), ref recordCount);
        Pager.RecordCount = recordCount;
        rptFiles.DataSource = dtMonthlyList;
        rptFiles.DataBind();
    }
    public string Cut(object title, int length)
    {
        if (title != null)
        {
            string _title = title.ToString();
            return _title.Length > length ? (_title.Substring(0, length) + "...") : _title;
        }
        return string.Empty;
    }
    protected void btnAdvancedSearch_Click(object sender, EventArgs e)
    {
        SearchClauseList = "1=1";
        if (tbDateStart.Text != string.Empty)
            SearchClauseList += string.Format(" AND {0} >= '{1}'", MonthlyDB.Entity.Monthly.SQLCOL_PUBLISHTIME, tbDateStart.Text);
        if (tbDateEnd.Text != string.Empty)
            SearchClauseList += string.Format(" AND {0}<=N'{1}'", MonthlyDB.Entity.Monthly.SQLCOL_PUBLISHTIME, tbDateEnd.Text);
        if (tbFileName.Text != string.Empty)
            SearchClauseList += string.Format(" AND {0} LIKE N'%{1}%'", MonthlyDB.Entity.Monthly.SQLCOL_FILENAME, tbFileName.Text.Replace("'", "''").Replace("%", "[%]"));
        
        BindData();
    }
}

